<?php
	class CommandModel
	{
		public static function add($station, $command, $arg)
		{
			$db = XDB::getDB('nuclide');
			$db->execute('INSERT INTO cmd(station, cmd, arg, time) VALUES(?, ?, ?, ?);', 
				array($station, $command, $arg, date("Y-m-d H:i:s")));
		}

		public static function query($station)
		{
			$db = XDB::getDB('nuclide');
			return $db->queryRow('SELECT id, cmd, arg, time FROM cmd WHERE station = ? AND result IS NULL ORDER BY time ASC LIMIT 1;',
				array($station));
		}

		public static function reply($id, $reply)
		{
			$db = XDB::getDB('nuclide');
			$db->execute('UPDATE cmd SET result = ? WHERE id = ?', array($reply, $id));
		}
	}

?>